package com.emoriarty.android.outilsresources.lists.overlaping;

import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.emoriarty.android.outilsresources.R;

public class SubmenuListFragment extends ListFragment {
	public final static String MOONS = "moons";
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		
		Bundle args = getArguments();
		
		if (args != null && args.containsKey(MOONS)) {
			ArrayAdapter<String> menuAdapter = new MoonsAdapter(args.getStringArray(MOONS));
			setListAdapter(menuAdapter);
		}
		
	}
	
	class MoonsAdapter extends ArrayAdapter<String> {
		public MoonsAdapter(String[] moons) {
			super(getActivity(), R.layout.overlap_submenu_list_item, moons);
		}
		
		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			if (convertView == null) {
				LayoutInflater inflater = getActivity().getLayoutInflater();
				convertView = inflater.inflate(R.layout.overlap_submenu_list_item, parent, false);
			}
			
			((TextView) convertView.findViewById(android.R.id.text1)).setText(getItem(position));
			
			return convertView;
		}
	}
}
